import time

from flask import jsonify
from flask import request

from utils.chat import chat
from . import api


@api.route('/chat', methods=['POST'])
def talk():
    start = time.time()
    data = request.json
    text = data['text']
    print('text: ' + text)
    result = chat(text)
    elapsed = time.time() - start
    elapsed = float(elapsed)
    return jsonify({'text': text, 'result': result, 'elapsed': elapsed})
